package com.komlin.msgpush.vivomsgpush;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;

import com.komlin.msgpush.KomlinPushManager;
import com.vivo.push.model.UPSNotificationMessage;
import com.vivo.push.sdk.OpenClientPushMessageReceiver;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;

/**
 * @Author lifq
 * 创建时间： 2019/6/1 14:04
 * 包名： com.komlin.msgpush.vivomsgpush
 * 功能描述：
 **/
public class PushMessageReceiverImpl extends OpenClientPushMessageReceiver {

    @Override
    public void onNotificationMessageClicked(final Context context, UPSNotificationMessage upsNotificationMessage) {
        /*long msgId;
        int customeContent;
        if (upsNotificationMessage != null) {
            msgId = upsNotificationMessage.getMsgId();
            customeContent = upsNotificationMessage.getSkipType();
            Map<String, String> params = upsNotificationMessage.getParams();
            String type = params.get("type");
            String data = params.get("data");
            try {
                JSONObject jsonObject = new JSONObject(data);
                final Intent intent = new Intent();
                //0校园公告1班级公告2校园通知3班级通知4问卷调查
                if ("0".equals(type)) {
                    intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.main.publics.SchoolNoticePublicActivity"));
                    intent.putExtra("flag", 2).putExtra("title", "校园公告").putExtra("type", 1);
                } else if ("1".equals(type)) {
                    intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.main.publics.SchoolNoticePublicActivity"));
                    intent.putExtra("flag", 2).putExtra("title", "班级公告").putExtra("type", 2);
                } else if ("2".equals(type)) {
                    intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.main.publics.SchoolNoticePublicActivity"));
                    intent.putExtra("flag", 1).putExtra("title", "校园通知").putExtra("type", 2);
                } else if ("3".equals(type)) {
                    intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.main.publics.SchoolNoticePublicActivity"));
                    intent.putExtra("flag", 1).putExtra("title", "班级通知").putExtra("type", 3);
                } else if ("4".equals(type)) {
                    intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.main.publics.SchoolNoticePublicActivity"));
                    intent.putExtra("flag", 4).putExtra("title", "问卷调查").putExtra("type", 2);
                } else if ("5".equals(type)) {
                    intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.new_leave.ApplyForLeaveListActivity"));
                    intent.putExtra("title", "我的请假");
                } else if ("6".equals(type)) {
                    intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.main.leave.LeaveStudentActivity"));
                    intent.putExtra("title", "批学生假");
                } else if ("7".equals(type)) {
                    intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.main.leave.LeaveTeachersActivity"));
                    intent.putExtra("title", "批假初审").putExtra("type", 1);
                } else if ("8".equals(type)) {
                    intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.main.leave.LeaveTeachersActivity"));
                    intent.putExtra("title", "批假终审").putExtra("type", 2);
                } else if ("9".equals(type)) {
                    intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.is_on_duty.DutyCalendarActivity"));
                } else if ("10".equals(type)) {
                    //intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.is_on_duty.DutyCalendarActivity"));
                } else if ("11".equals(type)) {
                    String classID = jsonObject.getString("classID");
                    intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.main.bed.BedroomMsgActivity"));
                    intent.putExtra("classId", classID);
                } else if ("12".equals(type)) {
                    intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.visitors.VisitorsListActivity"));
                } else if ("13".equals(type)) {
                    intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.leave_message.LeaveMessageTeacherActivity"));
                } else if ("14".equals(type)) {
                    //学生留言
                    intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.leave_message.LeaveMessageStudentActivity"));
                } else if ("15".equals(type)) {
                    //教师带队 com.komlin.commonedition.ui.lead_the_tean
                    intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.lead_the_tean.TeachersLeadTheTeamActivity"));
                } else if ("16".equals(type)) {
                    //待处理保修
                    intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.main.matters.MattersListActivity"));
                } else if ("17".equals(type)) {
                    //安全巡查 com.komlin.commonedition.ui.safety_patrol
                    intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.safety_patrol.SafetyPatrolActivity"));
                } else if ("18".equals(type)) {
                    //代换课申请 com.komlin.commonedition.ui.safety_patrol
                    intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.lesson_change.LessonChangeListActivity"));
                } else if ("19".equals(type)) {
                    //开发者邀请 com.komlin.commonedition.ui.safety_patrol
                    intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.lesson_change.LessonChangeInviteActivity"));
                } else {
                    intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.main.MainActivity"));
                }
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                intent.setAction("android.intent.action.VIEW");
                new Timer().schedule(new TimerTask() {
                    @Override
                    public void run() {
                        context.startActivity(intent);
                    }
                }, 1000);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            Log.e("NPL", "获取通知内容如下:msgId = " + msgId + ";customeContent=" + customeContent);
        }*/
    }

    @Override
    public void onReceiveRegId(Context context, String registerId) {
        if (TextUtils.isEmpty(registerId)) {
            //获取regId失败
            Log.e("NPL", "获取RegId失败");
        } else {
            //SP_Utils.saveString("vivoRegisterId",s);
            if (KomlinPushManager.getInstance().revicer != null) {
                KomlinPushManager.getInstance().revicer.onToken(registerId);
                Log.e("NPL", "vivo消息推送成功，获取RegId成功，regid = " + registerId);
            }
        }
    }
}
